package com.mifengs.mall.adapter;

import android.net.Uri;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lzy.imagepicker.bean.ImageItem;
import com.mifengs.mall.R;

import java.io.File;
import java.util.List;

/**
 * Created by lihaoqi on 2018/3/26.
 */

public class ContractRvAdapter extends BaseQuickAdapter<ImageItem,BaseViewHolder> {

    public ContractRvAdapter() {
        super(R.layout.item_contract_add);
    }

    public ContractRvAdapter(@Nullable List<ImageItem> data) {
        super(R.layout.item_contract_add, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ImageItem item) {
        ImageView imageView = helper.getView(R.id.iv_photo);
        ProgressBar pgBar = helper.getView(R.id.pg_bar);
        if(item.addTime!=1){
            pgBar.setVisibility(View.VISIBLE);
        }else{
            pgBar.setVisibility(View.GONE);
        }

        if(TextUtils.isEmpty(item.path)){
            Glide.with(mContext)
                    .load(R.drawable.ic_item_add)
                    .into(imageView);
            helper.setVisible(R.id.iv_delete,false);
            pgBar.setVisibility(View.GONE);
        }else {
            Glide.with(mContext)                             //配置上下文
                    .load(Uri.fromFile(new File(item.path)))      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                    .error(R.drawable.ic_default_image)           //设置错误图片
                    .placeholder(R.drawable.ic_default_image)     //设置占位图片
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .into(imageView);
            helper.setVisible(R.id.iv_delete,true);
            helper.addOnClickListener(R.id.rl_delete);
        }
    }


}
